<?php

namespace app\admin\model\scanwork;

use think\Model;

class QualityImage extends Model
{
    // 表名
    protected $name = 'scanwork_quality_image';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'image_type_text',
    ];
    
    public function getImageTypeList()
    {
        return ['1' => __('合格'), '2' => __('不合格'), '3' => __('返工')];
    }

    public function getImageTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['image_type']) ? $data['image_type'] : '');
        $list = $this->getImageTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    // 关联质检记录
    public function qualityRecord()
    {
        return $this->belongsTo('app\admin\model\scanwork\QualityRecord', 'record_id', 'id');
    }
}
